package com.mars.foodserver.controller.app;

import com.mars.foodserver.controller.common.BaseController;
import com.mars.foodserver.request.FoodRequest;
import com.mars.foodserver.request.FoodTypeRequest;
import com.mars.foodserver.response.result.R;
import com.mars.foodserver.service.IFoodService;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;

import java.util.Arrays;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wq
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/food")
@AllArgsConstructor
public class FoodController extends BaseController {

    final IFoodService foodService;

    /**
     * 美食推荐
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/recommend")
    private R recommend(@RequestBody FoodRequest request) {
        request.setUserId(getUserId());
        return R.success(foodService.page(request));
    }


    /**
     * 批量查询
     *
     * @return R
     */
    @GetMapping("/selectBatch")
    private R selectBatch() {
        return R.success(foodService.selectBatch(Arrays.asList(3, 4, 5)));
    }

    /**
     * 我的食谱
     *
     * @return 请求参数
     */
    @GetMapping("/mineFoods")
    private R mineFoods() {
        return R.success(foodService.mineFoods(getUserId()));
    }


    /**
     * 发布美食
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/publish")
    public R publish(@RequestBody FoodRequest request) {
        foodService.publish(getUserId(), request);
        return R.success();
    }


    /**
     * 获取美食详情
     *
     * @param id ID
     * @return R
     */
    @GetMapping("/detail")
    public R acquireDetail(Integer id) {
        return R.success(foodService.acquireDetail(getUserId(), id));
    }


    /**
     * 分类获取详情
     *
     * @param foodCategoryId foodCategoryId
     * @return R
     */
    @GetMapping("/categoryDetail")
    public R categoryDetailList(Integer foodCategoryId) {
        return R.success(foodService.categoryDetailList(foodCategoryId));
    }


}
